﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SPWP.OpinionPoll
{
    class DateComparerExpire : IComparer<PollMaster>
    {
        public int Compare(PollMaster a, PollMaster b)
        {

            DateTime x;
            DateTime.TryParse(a.ExpireOn.ToString(), out x);

            DateTime y;
            DateTime.TryParse(b.ExpireOn.ToString(), out y);

            if (x == null)
            {
                if (y == null)
                {
                    // If x is null and y is null, they're 
                    // equal.  
                    return 0;
                }
                else
                {
                    // If x is null and y is not null, y 
                    // is greater.  
                    return 1;
                }
            }
            else
            {
                // If x is not null... 
                // 
                if (y == null)
                // ...and y is null, x is greater.
                {
                    return -1;
                }
                else
                {
                    // ...and y is not null...

                    int result = DateTime.Compare(x, y);

                    if (result < 0)
                        return 1; // "is earlier than";
                    else if (result == 0)
                        return 0; // "is the same time as";
                    else
                        return -1; // "is later than";


                }
            }
        }
    }
}
